package com.xhg.mqtt.listener;

import com.xhg.mqtt.util.CommonUtil;
import com.xhg.mqtt.util.LogUtil;

/**
 * 日志工厂
 *
 * @author E.T
 * @version 1.0
 * @Description
 * @date 2018-08-02 13:49
 * @updateby
 * @updatedate
 * @since 1.0
 */
public class MqttLoggerFactory {

    private static MqttLogger mqttLogger;

    public static void createLogger(MqttLogger mqttLogger) {
        MqttLoggerFactory.mqttLogger = mqttLogger;
    }

    public static void debug(String logger) {
        if (mqttLogger != null) {
            mqttLogger.debug(logger);
        }else{
            LogUtil.print(logger);
        }
    }

    public static void info(String logger) {
        if (mqttLogger != null) {
            mqttLogger.info(logger);
        }else{
            LogUtil.print(logger);
        }
    }

    public static void warn(String logger) {
        if (mqttLogger != null) {
            mqttLogger.warn(logger);
        }else{
            LogUtil.print(logger);
        }
    }

    public static void warn(String logger,Throwable throwable) {
        if (mqttLogger != null) {
            mqttLogger.warn(logger,CommonUtil.getThrowableStrRep(throwable),throwable);
        }else{
            LogUtil.print(logger+CommonUtil.getThrowableStrRep(throwable));
        }
    }

    public static void error(String logger) {
        if (mqttLogger != null) {
            mqttLogger.error(logger);
        }else{
            LogUtil.print(logger);
        }
    }
    public static void error(String logger,Throwable throwable) {
        if (mqttLogger != null) {
            mqttLogger.error(logger,CommonUtil.getThrowableStrRep(throwable),throwable);
        }else{
            LogUtil.print(logger+CommonUtil.getThrowableStrRep(throwable));
        }
    }
}
